<template>
	<view class="my-form">
		<view class="form-item">
			<u--textarea v-model="comment" placeholder="请输入你的评论内容..." border="none"></u--textarea>
		</view>
		<view class="form-item">
			<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="5" multiple :maxCount="9"
				:previewFullImage="true">
			</u-upload>
		</view>
		<view class="form-item">
			<u-button type="primary" text="发表" @click="setComment"></u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		set_comment
	} from '@/api/contents/comment/comment.js'
	export default {
		data() {
			return {
				comment: '',
				fileList: [],
			};
		},
		methods: {
			afterRead(file) {
				this.fileList = [...this.fileList, ...file.file]
			},
			deletePic(event) {
				this.fileList.splice(event.index, 1)
			},
			//发表评论
			setComment() {
				const fileUrl = this.fileList.map(item => item.url)
				set_comment({
					content:this.comment,
					files:fileUrl.join(',')
				}).then(res => {
					if(res.code==1){
						this.$refs.uToast.show({
							message: res.msg,
							complete() {
								uni.navigateBack();
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.my-form {
		padding: 30upx;

		.form-item {}
	}
</style>
